package com.hex.ds.hdrs.warn.controller;

import com.hex.bigdata.hbda.base.Page;
import com.hex.bigdata.hbda.service.dto.UserDto;
import com.hex.ds.hdrs.common.page.PageData;
import com.hex.ds.hdrs.warn.dto.WarnConfDto;
import com.hex.ds.hdrs.warn.po.WarnConf;
import com.hex.ds.hdrs.warn.service.WarnConfService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lwz
 * @date 2021-01-25
 * @des
 */
@RestController
@RequestMapping("/api/warnConf")
@Slf4j
@ApiOperation("预警设置")
public class WarnConfController {

    @Autowired
    private WarnConfService warnConfService;

    @ApiOperation("查询告警配置")
    @GetMapping("/selectPages")
    public ResponseEntity select(WarnConf warnConf, Page page) {
        log.debug("进入了【WarnConfController】的select方法");
        PageData pageData = new PageData(this.warnConfService.qryWarnConfList(warnConf, page), page);
        return new ResponseEntity(pageData, HttpStatus.OK);
    }

    @ApiOperation("添加告警配置")
    @PostMapping("/add")
    public ResponseEntity<Object> add(@RequestBody WarnConfDto warnConfDto) {
        log.debug("添加告警配置【WarnConfController.add】warnConfDto【{}】", warnConfDto);
        this.warnConfService.add(warnConfDto);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @ApiOperation("获取所有人员列表")
    @GetMapping(value = "getUserList")
    public ResponseEntity<Object> getUserList() {
        log.debug("获取所有人员【WarnConfController.getUserList】");
        List<UserDto> userList = this.warnConfService.getUserList();
        return new ResponseEntity<>(userList, HttpStatus.OK);
    }

    @ApiOperation("删除")
    @DeleteMapping("/del")
    public ResponseEntity<Object> del(@RequestBody List<String> pkIds) {
        log.debug("【WarnConfController.del】pkIds={}", pkIds);
        this.warnConfService.del(pkIds);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("通过pkId查询详细信息")
    @GetMapping("/getEditWarnConf")
    public ResponseEntity<Object> getEditWarnConf(@RequestParam String pkId) {
        log.debug("【WarnConfController的getEditWarnConf】pkId={}", pkId);
        return new ResponseEntity(this.warnConfService.getEditWarnConf(pkId), HttpStatus.OK);
    }

    @ApiOperation("修改")
    @PostMapping("/edit")
    public ResponseEntity<Object> edit(@RequestBody WarnConfDto warnConfDto) {
        log.debug("【WarnConfController的edit】warnConfDto={}", warnConfDto);
        this.warnConfService.edit(warnConfDto);
        return new ResponseEntity("修改成功", HttpStatus.OK);
    }

    @ApiOperation("分页查询应用告警配置")
    @GetMapping("/appSelectPages")
    public ResponseEntity appSelectPages(WarnConf warnConf, Page page) {
        log.debug("进入了【WarnConfController】的appSelectPages方法");
        PageData pageData = new PageData(this.warnConfService.appSelectPages(warnConf, page), page);
        return new ResponseEntity(pageData, HttpStatus.OK);
    }

    @ApiOperation("添加应用告警配置")
    @PostMapping("/addAppWarnConf")
    public ResponseEntity<Object> addAppWarnConf(@RequestBody WarnConfDto warnConfDto) {
        log.debug("添加应用告警配置【WarnConfController.addAppWarnConf】warnConfDto={}", warnConfDto);
        this.warnConfService.addAppWarnConf(warnConfDto);
        return new ResponseEntity<>("添加成功", HttpStatus.OK);
    }

    @ApiOperation("检查告警描述是否重复")
    @PostMapping("/validateParam")
    public ResponseEntity<Object> validateParam(@RequestBody WarnConfDto warnConfDto) {
        log.debug("检查告警描述是否重复【WarnConfController.validateParam】warnConfDto={}", warnConfDto);
        return new ResponseEntity<>(this.warnConfService.validateParam(warnConfDto), HttpStatus.OK);
    }
}
